<?php
class TalleresController extends AppController {

	var $name = 'Talleres';

	function index() {
		$this->Tallere->recursive = 0;
		$this->set('talleres', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid tallere', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('tallere', $this->Tallere->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Tallere->create();
			if ($this->Tallere->save($this->data)) {
				$this->Session->setFlash(__('The tallere has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The tallere could not be saved. Please, try again.', true));
			}
		}
		$users = $this->Tallere->User->find('list');
		$entidadesTerritoriales = $this->Tallere->EntidadesTerritoriale->find('list');
		$this->set(compact('users', 'entidadesTerritoriales'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid tallere', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Tallere->save($this->data)) {
				$this->Session->setFlash(__('The tallere has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The tallere could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Tallere->read(null, $id);
		}
		$users = $this->Tallere->User->find('list');
		$entidadesTerritoriales = $this->Tallere->EntidadesTerritoriale->find('list');
		$this->set(compact('users', 'entidadesTerritoriales'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for tallere', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Tallere->delete($id)) {
			$this->Session->setFlash(__('Tallere deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Tallere was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
